package com.lxl.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;

import com.lxl.service.BookUserService;
import com.lxl.service.impl.BookUserServiceImpl;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.awt.Cursor;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author 刘星鹭
 * @Email liuxinglumail@163.com
 * @version 创建时间： 2014年9月12日 下午3:22:11
 */

public class DeleteBookUser extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField username;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DeleteBookUser frame = new DeleteBookUser();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public DeleteBookUser() {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				ViewBookUser.main(new String[1]);
			}
		});
		setFont(new Font("微软雅黑", Font.PLAIN, 12));
		setTitle("图书管理系统");
		setBounds(100, 100, 450, 175);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		username = new JTextField();
		username.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		username.setBounds(178, 40, 221, 23);
		panel.add(username);
		username.setColumns(10);

		JLabel label = new JLabel("请输入欲删除的用户账号：");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label.setBounds(24, 44, 144, 15);
		panel.add(label);

		JButton btnNewButton = new JButton("删除");
		btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				if (username.getText().equals(""))
					JOptionPane.showMessageDialog(null, "请填写用户账号！");
				else {
					Integer name = Integer.parseInt(username.getText());
					BookUserService bookUserService = new BookUserServiceImpl();
					bookUserService.delete(name);
					JOptionPane.showMessageDialog(null, "删除成功！");
				}
			}
		});
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.setBounds(153, 83, 93, 23);
		panel.add(btnNewButton);
	}
}
